﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BiffenGUI.BiffenService;
using System.ServiceModel;

namespace BiffenGUI.UserControls
{
    public partial class SearchMovies : UserControl
    {

        public IBiffenService Service;
        public MemberAddBookingCurrent BookingFrame { get; set; }
        public TabControl ParentTabControl { get; set; }

        public SearchMovies()
        {
            InitializeComponent();
        }

        private void SearchMovies_Load(object sender, EventArgs e)
        {
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string query = txtSearch.Text;

            var searchParams = GetSearchParams();

            try
            {
                var movies = Service.SearchMovies(searchParams, query);
                movieList1.BuildMovieList(movies, BookingFrame);
            }
            catch (FaultException<EmptyParameterFault>)
            {
                MessageBox.Show("Du skal vælge mindst et felt at søge i.");
            }
        }

        private List<string> GetSearchParams() {
            var param = new List<String>();

            if (chkbActors.Checked)
            {
                param.Add("Actors");
            }

            if (chkbSummary.Checked)
            {
                param.Add("Summary");
            }

            if (chkbDirectors.Checked)
            {
                param.Add("Directors");
            }

            if (chkbTitle.Checked)
            {
                param.Add("Title");
            }

            return param;
        }

        
    }
}
